﻿using PubSubGeneric.WCFContracts;
using PubSubGeneric.WCFContracts.Utils;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Json;
using System.Text;
using System.Threading.Tasks;

namespace PubSubGeneric.WCFSubcriptionServer
{
    internal class WCFSubscriberAdapter<T> : ISubscriber<T>, IWCFSubscriberAdapter
    {
        public IWCFSubscriber WCFSubscriber { get; set; }

        public void OnTopicPublished(string topicName, T args)
        {
            string objstr = WCFSerializer.Serialize(args, typeof(T));
            WCFSubscriber.OnTopicPublished(topicName, objstr, Util.GetFullTypeName<T>());
        }

        public override int GetHashCode()
        {
            return WCFSubscriber.GetHashCode();
        }

        public override bool Equals(object obj)
        {
            WCFSubscriberAdapter<T> other = obj as WCFSubscriberAdapter<T>;
            if (other != null)
                return this.WCFSubscriber.Equals(other.WCFSubscriber);
            return false;
        }
    }
}
